package com.hsingh.eclipse.mercury;

import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.PlatformUI;

import com.hsingh.eclipse.mercury.extensionpoint.definition.ITask;

public class TaskLabelProvider implements ILabelProvider {
  ILabelDecorator decorator = PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator();

  private boolean provideDetails = false;

  public TaskLabelProvider(boolean provideDetails) {
    this.provideDetails = provideDetails;
  }

  @Override
  public void addListener(ILabelProviderListener listener) {}

  @Override
  public void dispose() {}

  @Override
  public boolean isLabelProperty(Object item, String property) {
    System.out.println("is label property called:" + item + ":" + property);
    return false;
  }

  @Override
  public void removeListener(ILabelProviderListener listener) {}

  @Override
  public Image getImage(Object obj) {
    if (obj instanceof ITask) {
      return ((ITask) obj).getImage();
    } else {
      return null;
    }
  }

  @Override
  public String getText(Object obj) {
    String text = "";
    if (obj instanceof ITask) {
      ITask searchItem = (ITask) obj;
      if (provideDetails) {
        text = searchItem.getDetailsLabel();
      } else {
        text = searchItem.getLabel();
      }
      text = decorator.decorateText(text, searchItem.getItem());
    }

    return text;
  }
}
